<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        body {
            background-color: rgb(165, 238, 213);
        }

        h1 {
            width: 260px;
            margin: 30px auto;
        }

        .info {
            width: 600px;
            margin: 16px auto;
            font-weight: 900;
            font-size: 20px;
        }

        input {
            width: 500px;
            height: 30px;
        }

        button {
            width:100px;
            height: 40px;
            border-radius: 10px;
            font-size: 20px;
        }

        .add {
            width: 90px;
            margin: 10px auto;
        }
    </style>
</head>

<body>
    <div id="app"></div>
    <template id="t1">
        <div>
            <h1>学生信息修改表</h1>
            <p class="info">
                姓名：
                <input type="text" v-model="users.username">
            </p>
            <p class="info">
                电话：
                <input type="text" v-model="users.phone">
            </p>
            <p class="add">
                <button @click="add()">保存</button>
            </p>

        </div>
    </template>
    <script src="./jquery.min.js"></script>
    <script src="./vue.min.js"></script>
    <script>
        var vm = new Vue({
            el: '#app',
            template: '#t1',
            data: function () {
                return {
                    users: {
                        username: '',
                        phone: '',
                        id: location.hash.replace('#', ''),
                    }
                }
            },
            created: function () {
                this.find();
            },
            methods: {
                find: function () {
                    var that = this;
                    $.get('/users/find', { id: this.users.id }).done(function (result) {
                        that.users.username = result.username,
                            that.users.phone = result.phone
                    });
                },
                add: function () {
                    $.post('/users/edit', this.users).done(function () {
                        location.href = "index.html";
                    });
                }
            }
        });
    </script>
</body>

</html>